package com.juyu.miliao.api.service;

import com.juyu.miliao.api.dao.redis.LineTimeRedisDao;
import com.juyu.miliao.api.dao.redis.ReceiveGiftSortRedisDao;
import com.juyu.miliao.api.dao.redis.usercache.UserCacheVo;
import com.juyu.miliao.api.dao.redis.usercache.UserInfoCache;
import com.juyu.miliao.api.domain.ReceiveGiftSortInfo;
import com.juyu.miliao.api.domain.vo.ReceiveGiftInfoByOutUserVo;
import com.juyu.miliao.api.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author xuanqicheng
 * @create 2019-28-14:33
 */
@Service
public class ReceiveGiftSortService {

    @Autowired
    private UserInfoCache userInfoCache;

    @Autowired
    private ReceiveGiftSortRedisDao receiveGiftSortRedisDao;

    @Autowired
    private LineTimeRedisDao lineTimeRedisDao;

    public Object getReceiveGiftSortList(int page, int pageSize, long inUserId) {

        int startNum = PageUtil.getOffset(page, pageSize);

        int endNum = (startNum+pageSize)-1;

        List<ReceiveGiftSortInfo> receiveGiftSortInfoList =receiveGiftSortRedisDao
                .getReceiveGiftSortByPage(startNum,endNum,inUserId);

        for(ReceiveGiftSortInfo receiveGiftSortInfo :receiveGiftSortInfoList ){
            UserCacheVo userCacheVo =userInfoCache.getUserCacheInfo(receiveGiftSortInfo.getOutUserId());
            Boolean bl = lineTimeRedisDao.hasKeyLine(receiveGiftSortInfo.getOutUserId() + "");
            if(bl!=null && bl){
                receiveGiftSortInfo.setOnLine(1);
            }else{
                receiveGiftSortInfo.setOnLine(2);
            }
            receiveGiftSortInfo.setOutUserNickName(userCacheVo.getNickName());
            receiveGiftSortInfo.setOutUserIcon(userCacheVo.getIcon());
            List<ReceiveGiftInfoByOutUserVo> giftList = receiveGiftSortRedisDao
                   .receiveGiftInfoByOutUserIdAndIncomeUserId(inUserId,receiveGiftSortInfo.getOutUserId());

            receiveGiftSortInfo.setGiftList(giftList);
        }


        return receiveGiftSortInfoList;
    }
}
